package fr.upstlse.glre.client.espacededie;

import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.google.gwt.user.client.rpc.AsyncCallback;

import fr.upstlse.glre.client.vo.user.UserVOGWT;

public abstract class AbstractEspaceDebie<TUser extends UserVOGWT> implements
		IEspaceDebie<TUser> {

	protected TUser user;
	protected Viewport viewport;
	protected AsyncCallback<TUser> userInformationAsyncCallBack;

	protected AbstractEspaceDebie() {
		viewport = new Viewport();

		viewport.setStyleName("my-border-layout");

		viewport.setLayout(new RowLayout());
		viewport.setBorders(false);
		viewport.setEnableScroll(true);
		
		userInformationAsyncCallBack = new AsyncCallback<TUser>() {
			public void onFailure(Throwable pCaught) {
				MessageBox
						.alert("Erreur", "Erreur getUser "
								+ pCaught.getMessage(), null);
			}

			public void onSuccess(TUser pResult) {
				setUser(pResult);
				createComponents();
				Info
						.display(
								"Information",
								"Succès du chargement de l'utilisateur",
								"");
			}
		};
	}

	public void createEspace(long lId) {
		getUserInformation(lId);
	}
	
	abstract protected void createComponents();
	
	abstract public void getUserInformation(long lId);
	
	public AsyncCallback<TUser> getUserInformationAsyncCallBack() {
		return userInformationAsyncCallBack;
	}

	public void setUserInformationAsyncCallBack(
			AsyncCallback<TUser> pUserInformationAsyncCallBack) {
		userInformationAsyncCallBack = pUserInformationAsyncCallBack;
	}

	public TUser getUser() {
		return user;
	}

	public void setUser(TUser pUser) {
		user = pUser;
	}

	public Viewport getViewport() {
		return viewport;
	}

	public void setViewport(Viewport viewport) {
		this.viewport = viewport;
	}
	
}
